﻿//ham main
#include"khaibao.h"

void main()
{
	int a[100], n, chon, tk;
	char tenfile[50];
	srand((unsigned)(time(NULL)));
	//menu lựa chọn.
	do
	{
		{
			cout << "menu lua chon \n";
			cout << "1. Nhap \n";
			cout << "2. Xuat \n";
			cout << "3. Tim Kiem \n";
			cout << "4. Dem \n";
			cout << "5. Tinh Tong \n";
			cout << "6. Tinh Trung Binh Cong \n";
			cout << "7. Sap Xep \n";
			cout << "0. Thoat \n";
		}
		cout << "nhap lua chon=";
		cin >> chon;
		switch (chon)
		{
		case 1: cout << "Nhap \n";
			int cv;
			do
			{
				{
					cout << "1. Nhap Tu Ban Phim \n";
					cout << "2. Nhap Ngau nhien \n";
				}
				cout << "nhap cong viec cv=";
				cin >> cv;
				switch (cv)
				{
				case 1: 
					 int cv2;
					do
					{
						{
							cout << "1. ghi file \n";
							cout << "2. doc file \n";
							cout << "0. Thoat \n";
						}
						cout << "nhap thao tac cv2=";
						cin >> cv2;
						switch (cv2)
						{

						case 1:
							nhapmang(a, n);
							cout << "\n Ban nhap vao ten tap tin \n";
							cin.ignore(1);
							cin.getline(tenfile, 50);
							Ghifile(tenfile, a, n);
							break;
						case 2:
							cout << "\n Ban nhap vao ten tap tin \n";
							cin.ignore(1);
							cin.getline(tenfile, 50);
							docfile(tenfile, a, n);
							break;
						}

					} while (cv2 != 0); 

					break;
				case 2: 
					int cv3;
					do
					{
						{
							cout << "1. ghi file \n";
							cout << "2. doc file \n";
							cout << "0. Thoat \n";
						}
						cout << "nhap thao tac cv3=";
						cin >> cv3;
						switch (cv3)
						{
						case 1:
							nhapngaunhien(a, n);
							cout << "\n Ban nhap vao ten tap tin \n";
							cin.ignore(1);
							cin.getline(tenfile, 50);
							Ghifile(tenfile, a, n);
							break;
						case 2:
							cout << "\n Ban nhap vao ten tap tin \n";
							cin.ignore(1);
							cin.getline(tenfile, 50);
							docfile(tenfile, a, n);
							break;
						}
			
					} while (cv3 != 0);
					break;
				}
				break;
			} while (cv != 0); 
			break;
		case 2: cout << "phan tu mang vua nhap:\n";
			xuatmang(a, n);
			break;
		case 3: cout << " cac thao tac Tim Kiem \n";
			do
			{
				{
					cout << "1. Tim Kiem cac phan tu duong \n";
					cout << "2. Tim kiem cac phan tu am \n";
					cout << "3. Tim kiem cac phan tu chan \n";
					cout << "4. Tim kiem cac phan tu le \n";
					cout << "5. Tim kiem cac phan tu la so nguyen to \n";
					cout << "6. Tim kiem cac phan tu la so hoan thien \n";
					cout << "7. tim kiem cac phan tu la so chinh phuong \n";
					cout << "8. Tim kiem cac phan tu la so chia het cho 2 khong chia het cho 3 \n";
					cout << "0. Thoat \n";
				}
				cout << "nhap tk=";
				cin >> tk;
				switch (tk)
				{
				case 1:
					cout << "cac phan tu duong cua mang:";
					timduong(a, n);
					cout << endl;
					break;
				case 2:cout << "cac phan tu am cua mang:";
					timam(a, n);
					cout << endl;
					break;
				case 3:	cout << "cac phan tu chan cua mang:";
					timchan(a, n);
					cout << endl;
					break;
				case 4:cout << "cac phan tu le cua mang:";
					timle(a, n);
					cout << endl;
					break;
				case 5:cout << "cac phan tu la so nguyen to co trong mang:";
					timngto(a, n);
					cout << endl;
				case 6:cout << " cac phan tu la so hoan thien co trong mang:";
					timhthien(a, n);
					cout << endl;
					break;
				case 7:cout << "cac phan tu la so chinh phuong co trong mang:";
					timchphuong(a, n);
					cout << endl;
					break;
				case 8:	cout << "cac phan tu chia het cho 2 va khong chia het cho 3 co trong mang:";
					timchiahetkhongchiahet(a, n);
					cout << endl;
					break;
				}
			} while (tk != 0);
			break;
		case 4: cout << "cac thao tac dem \n";
			int cv1;
			do
			{
				{
					cout << "1. dem cac phan tu duong \n";
					cout << "2. dem cac phan tu am \n";
					cout << "3. dem cac phan tu chan \n";
					cout << "4. dem cac phan tu le \n";
					cout << "5. dem cac phan tu la so nguyen to \n";
					cout << "6. dem cac phan tu la so hoan thien \n";
					cout << "7. dem cac phan tu la so chinh phuong \n";
					cout << "8. dem cac phan tu la so chia het cho 2 khong chia het cho 3 \n";
					cout << "0. Thoat \n";
				}
				cout << "nhap cong viec cv1=";
				cin >> cv1;
				switch (cv1)
				{
				case 1:int dd;
					dd = demduong(a, n);
					cout << " so luong phan tu duong cua mang:" << dd << endl;
					break;
				case 2:int da;
					da = demam(a, n);
					cout << " so luong phan tu am cua mang:" << da << endl;
					break;
				case 3:int dc;
					dc = demchan(a, n);
					cout << " so luong phan tu chan cua mang:" << dc << endl;
					break;
				case 4:int dl;
					dl = demle(a, n);
					cout << " so luong phan tu le cua mang:" << dl << endl;
					break;
				case 5:int dnt;
					dnt = demngto(a, n);
					cout << "so luong phan tu la so nguyen to trong mang:" << dnt << endl;
					break;
				case 6: int dht;
					dht = demhthien(a, n);
					cout << "so luong phan tu la so hoan thien trong mang:" << dht << endl;
					break;
				case 7:int dcp;
					dcp = demchphuong(a, n);
					cout << "so luong phan tu la cac so chinh phuong co trong mang:" << dcp << endl;
					break;
				case 8:int dhkh;
					dhkh = demchiahetkhongchiahet(a, n);
					cout << "so luong phan tu chia het cho 2 khong chia het cho 3 co trong mang:" << dhkh << endl;
					break;
				}
			} while (cv1 != 0);
			break;
		case 5: cout << "cac thao tac tinh tong \n";
			int tt;
			do
			{
				{
					cout << "1. tinh tong cac phan tu duong \n";
					cout << "2. tinh tong cac phan tu am \n";
					cout << "3. tinh tong cac phan tu chan \n";
					cout << "4. tinh tong cac phan tu le \n";
					cout << "5. tinh tong cac phan tu la so nguyen to \n";
					cout << "6. tinh tong cac phan tu la so hoan thien \n";
					cout << "7. tinh tong cac phan tu la so chinh phuong \n";
					cout << "8. tinh tong cac phan tu la so chia het cho 2 khong chia het cho 3 \n";
					cout << "0. Thoat \n";
				}
				cout << "nhap cong viec tt=";
				cin >> tt;
				switch (tt)
				{
				case 1:int td;
					td = tongduong(a, n);
					cout << "tong phan tu duong cua mang:" << td << endl;
					break;
				case 2:int ta;
					ta = tongam(a, n);
					cout << " tong phan tu am cua mang:" << ta << endl;
					break;
				case 3:int tc;
					tc = tongchan(a, n);
					cout << " tong phan tu chan cua mang:" << tc << endl;
					break;
				case 4:int tl;
					tl = tongle(a, n);
					cout << "tong phan tu le cua mang:" << tl << endl;
					break;
				case 5:int tnt;
					tnt = tongngto(a, n);
					cout << "tong phan tu la so nguyen to trong mang:" << tnt << endl;
					break;
				case 6: int tht;
					tht = tonghthien(a, n);
					cout << "tong phan tu la so hoan thien trong mang:" << tht << endl;
					break;
				case 7:int tcp;
					tcp = tongchphuong(a, n);
					cout << "tong phan tu la cac so chinh phuong co trong mang:" << tcp << endl;
					break;
				case 8:int thkh;
					thkh = tongchiahetkhongchiahet(a, n);
					cout << "tong phan tu chia het cho 2 khong chia het cho 3 co trong mang:" << thkh << endl;
					break;
				}
			} while (tt != 0);
			break;
		case 6: cout << "cac thao tac tinhs trung binh cong \n";
			int tb;
			do
			{
				{
					cout << "1. tinh trung binh cong cac phan tu duong \n";
					cout << "2. tinh trung binh cong cac phan tu am \n";
					cout << "3. tinh trung binh cong cac phan tu chan \n";
					cout << "4. tinh trung binh cong cac phan tu le \n";
					cout << "5. tinh trung binh cong cac phan tu la so nguyen to \n";
					cout << "6. tinh trung binh cong cac phan tu la so hoan thien \n";
					cout << "7. tinh trung binh cong cac phan tu la so chinh phuong \n";
					cout << "8. tinh trung binh cong cac phan tu la so chia het cho 2 khong chia het cho 3 \n";
					cout << "0. Thoat \n";
				}
				cout << "nhap cong viec tb=";
				cin >> tb;
				switch (tb)
				{
				case 1:float tbd;
					tbd = tbcduong(a, n);
					cout << "trung binh cong cac phan tu duong cua mang:" << tbd << endl;
					break;
				case 2:float tba;
					tba = tbcam(a, n);
					cout << " trung binh cong cac phan tu am cua mang:" << tba << endl;
					break;
				case 3:float tbc;
					tbc = tbcchan(a, n);
					cout << " trung binh cong cac phan tu chan cua mang:" << tbc << endl;
					break;
				case 4:float tbl;
					tbl = tbcle(a, n);
					cout << "trung binh cong cac phan tu le cua mang:" << tbl << endl;
					break;
				case 5:float tbnt;
					tbnt = tbcngto(a, n);
					cout << "trung binh cong cac phan tu la so nguyen to trong mang:" << tbnt << endl;
					break;
				case 6: float tbht;
					tbht = tbchthien(a, n);
					cout << "trung binh cong cac phan tu la so hoan thien trong mang:" << tbht << endl;
					break;
				case 7:float tbcp;
					tbcp = tbcchphuong(a, n);
					cout << "trung binh cong cac phan tu la cac so chinh phuong co trong mang:" << tbcp << endl;
					break;
				case 8:float
					tbhkh;
					tbhkh = tbcchiahetkhongchiahet(a, n);
					cout << "trung binh cong cac phan tu chia het cho 2 khong chia het cho 3 co trong mang:" << tbhkh << endl;
					break;
				}
			} while (tb != 0);
			break;
		case 7: cout << "cac thao tac sap xep \n";
			int sx;
			do
			{
				{
					cout << "1. sap xep tang \n";
					cout << "2. sap xep giam \n";
					cout << "0. thoat \n";
				}
				cout << "nhap cong viec sx=";
				cin >> sx;
				switch (sx)
				{
				case 1:cout << "sap xep cac phan tu mang theo dieu kien tang \n";
					int st;
					do
					{
						{
							cout << "1. sap xep mang tang \n";
							cout << "2. sap xep mang tang theo cac phan tu duong \n";
							cout << "3. sap xep mang tang theo cac phan tu am \n";
							cout << "4. sap xep mang tang theo cac phan tu chan \n";
							cout << "5. sap xep mang tang theo cac phan tu le \n";
							cout << "6. sap xep mang tang theo cac phan tu la so nguyen to \n";
							cout << "7. sap xep mang tang theo cac phan tu la so hoan thien \n";
							cout << "8. sap xep mang tang theo cac phan tu la so chinh phuong \n";
							cout << "9. sap xep mang tang theo cac phan tu la so chia het cho 2 va khong chia het cho 3 \n";
							cout << "0. Thoat \n";
						}
						cout << "nhap lua chon st=";
						cin >> st;
						switch (st)
						{
						case 1:	cout << "sap xep mang tang :\n";
							sapxeptang(a, n);
							break;
						case 2:cout << "sap xep mang tang theo dieu kien la so duong :\n";
							sxduongtang(a, n);
							break;
						case 3:cout << "sap xep mang tang theo dieu kien la so am :\n";
							sxamtang(a, n);
							break;
						case 4:cout << "sap xep mang tang theo dieu kien la so chan :\n";
							sxchantang(a, n);
							break;
						case 5: cout << "sap xep mang tang theo dieu kien la so le:\n";
							sxletang(a, n);
							break;
						case 6: cout << "sap xep mang tang theo dieu kien la so nguyen to:\n";
							sxngtotang(a, n);
							break;
						case 7: cout << "sap xep mang tang theo dieu kien la so hoan thien:\n";
							sxhthientang(a, n);
							break;
						case 8: cout << "sap xep mang tang theo dieu kien la so chinh phuong:\n";
							sxchphuongtang(a, n);
							break;
						case 9:cout << "sap xep mang tang theo dieu kien chia het cho 2 va khong chia het cho 3:\n";
							sxchiahetvakhongchiahettang(a, n);
							break;
						
							
						}
					} while (st != 0);
					break;
				case 2:cout << "sap xep cac phan tu mang thep dieu kien giam \n";
					int sg;
					do
					{
						{
							cout << "1. sap xep mang giam \n";
							cout << "2. sap xep mang giam theo cac phan tu duong \n";
							cout << "3. sap xep mang giam theo cac phan tu am \n";
							cout << "4. sap xep mang giam theo cac phan tu chan \n";
							cout << "5. sap xep mang giam theo cac phan tu le \n";
							cout << "6. sap xep mang giam theo cac phan tu la so nguyen to \n";
							cout << "7. sap xep mang giam theo cac phan tu la so hoan thien \n";
							cout << "8. sap xep mang giam theo cac phan tu la so chinh phuong \n";
							cout << "9. sap xep mang giam theo cac phan tu la so chia het cho 2 va khong chia het cho 3 \n";
							cout << "0. Thoat \n";
						}
						cout << "nhap lua chon sg=";
						cin >> sg;
						switch (sg)
						{
						case 1:cout << "sap xep mang giam :\n";
							sapxepgiam(a, n);
							break;
						case 2:cout << "sap xep mang giam theo dieu kien la so duong :\n";
							sxduonggiam(a, n);
							break;
						case 3:cout << "sap xep mang giam theo dieu kien la so am :\n";
							sxamgiam(a, n);
							break;
						case 4:cout << "sap xep mang giam theo dieu kien la so chan :\n";
							sxchangiam(a, n);
							break;
						case 5: cout << "sap xep mang giam theo dieu kien la so le :\n";
							sxletang(a, n);
							break;
						case 6:cout << "sap xep mang giam theo dieu kien la so nguyen to :\n";
							sxngtogiam(a, n);
							break;
						case 7: cout << "sap xep mang giam theo dieu kien la so hoan thien :\n";
							sxhthiengiam(a, n);
							break;
						case 8: cout << "sap xep mang giam theo dieu kien la so chinh phuong :\n";
							sxchphuonggiam(a, n);
							break;
						case 9:cout << "sap xep mang giam theo dieu kien la so chia het cho 2 va khong chia het cho 3 :\n";
							sxchiahetvakhongchiahetgiam(a, n);
							break;
						}
					} while (sg != 0);
					break;
				}
			} while (sx != 0);
			break;
		}
	} while (chon != 0);

	system("pause");
}
